﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class FrontEnd_Control_Users_ThongTinCaNhan
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'lay ra so tin cua User da post trong ngay
            ltrSoTinSMS.Text = 0
            Dim _CreatorId As Integer = Session("UserId")
            Dim _date As Date = Now.Date
            Using _data As New VSEntities
                Dim p = (From q In _data.RaoVats Where q.CreatorId = _CreatorId And q.Created > _date Select q.RaovatId).Count
                Dim k = (From q In _data.RaoVats Where q.CreatorId = _CreatorId And q.Modified > _date Select q.RaovatId).Count

                If Session("UserVip") = 1 Then
                    ltrSoTinThem.Text = 5 - p

                    ltrSoLanUp.Text = 5 - k
                ElseIf Session("UserVip") = 2 Then
                    ltrSoTinThem.Text = 10 - p
                    ltrSoLanUp.Text = 10 - k
                ElseIf Session("UserVip") = 3 Then
                    ltrSoTinThem.Text = 25 - p
                    ltrSoLanUp.Text = 25 - k
                Else
                    ltrSoTinThem.Text = 1 - p
                    ltrSoLanUp.Text = 1 - k
                End If



                Dim h = (From q In _data.Users Where q.UserId = _CreatorId Select q).FirstOrDefault
                If Not h Is Nothing Then
                    If Not h.Vip Is Nothing Then
                        ltrLoaiTaiKhoan.Text = "Vip " & h.Vip.ToString
                        'update 
                        If h.bActiveVip Is Nothing Then
                            h.bActiveVip = Now.Date
                            _data.SaveChanges()
                        End If

                        If Not h.bActiveVip Is Nothing Then
                            ltrExpire.Text = "<i>hết hạn: " & CType(h.bActiveVip, Date).AddMonths(h.ThoiHan1.Sothang).ToString("dd/MM/yyyy") & "</i>"
                        End If

                    Else
                        ltrLoaiTaiKhoan.Text = "Thông thường"

                    End If
                End If
                Session("SoTinUp") = ltrSoLanUp.Text
                Session("SoTinThem") = ltrSoTinThem.Text


            End Using

        End If
    End Sub
End Class
